// serch-result.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active_nav:0,// 导航
    note:[
    ],
    goods:[
    ]
  },
  input(e){
    this.setData({
      inputValue : e.detail.value
    })
  },
  nav(e){
    this.setData({
      active_nav: e.target.dataset.id
    })
  },
  onLoad(options){
    let keyword = options.keyword
    this.setData({
      inputValue: keyword
    })
    this.search(keyword)
  },
  search(keyword, sale, comment, create_time, follow){
    wx.showLoading({
      title: '正在搜索...',
      mask: true
    })
    let baseUrl = getApp().globalData.baseUrl,
        access_token = getApp().globalData.access_token,
        self = this
    keyword = keyword instanceof String ? keyword: this.data.inputValue 
    sale = sale ? sale: ''
    comment = comment ? comment: ''
    create_time = create_time ? create_time:''
    follow = follow ? follow: ''
    wx.request({
      url: baseUrl + '/Index/search',
      method: 'GET',
      data: { access_token, keyword, sale, comment, create_time, follow},
      success: data => {
        wx.hideLoading()
        self.setData({
          data: data.data.data
        })
      }
    })
  },
  sort(e){
    wx.showLoading({
      title: '正在加载...',
    })
    console.log(e.currentTarget.dataset)
    let name = e.currentTarget.dataset.name,
        baseUrl = getApp().globalData.baseUrl,
        access_token = getApp().globalData.access_token,
        self = this
    self.setData({
      [name]: !self.data[name]
    })
    wx.request({
      url: baseUrl + '/Index/search',
      data: {
        [name]: self.data[name]?'desc':'asc',
        access_token
      },
      method: 'GET',
      success: data => {
        wx.hideLoading()
        self.setData({
          data: data.data.data
        })
      }
    })
  },
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh()
  },

})